﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.SFA.Server.BusinessRule.System;
/// <summary>
///OrgHelper 的摘要说明
/// </summary>
public class OrgHelper
{
    public OrgHelper()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    /// <summary>
    /// 根据部门获取所有的用户
    /// </summary>
    /// <param name="domainid"></param>
    /// <param name="orgvalues"></param>
    /// <param name="dropdownlist"></param>
    public static void BindAllUsersDDL(decimal domainid, string orgvalues, DropDownList dropdownlist)
    {
        try
        {
            dropdownlist.Items.Clear();
            dropdownlist.DataSource = new UserManager().GetAllUsersForDDL(domainid, orgvalues);
            dropdownlist.DataTextField = "CODENAME";
            dropdownlist.DataValueField = "ID";
            dropdownlist.DataBind();
            dropdownlist.Items.Insert(0, new ListItem("--所有--", ""));
        }
        catch
        {

        }

    }

    /// <summary>
    /// 根据部门获取巡店督导
    /// </summary>
    /// <param name="domainid"></param>
    /// <param name="orgvalues"></param>
    /// <param name="dropdownlist"></param>
    public static void BindUsersDDL(decimal domainid, string orgvalues, DropDownList dropdownlist)
    {
        try
        {
            //
            dropdownlist.Items.Clear();
            dropdownlist.DataSource = new MobileUserManager().Load(domainid, orgvalues);
            dropdownlist.DataTextField = "CODENAME";
            dropdownlist.DataValueField = "ID";
            dropdownlist.DataBind();
            dropdownlist.Items.Insert(0, new ListItem("--所有--", ""));
        }
        catch
        {
        }
    }

    /// <summary>
    /// 根据部门获取巡店督导
    /// </summary>
    /// <param name="domainid"></param>
    /// <param name="orgvalues"></param>
    /// <param name="dropdownlist"></param>
    public static void BindUsersDDL(decimal domainid, string orgvalues, DropDownList dropdownlist,string selfid)
    {
        try
        {
            //
            dropdownlist.Items.Clear();
            dropdownlist.DataSource = new MobileUserManager().Load(domainid, orgvalues,selfid);
            dropdownlist.DataTextField = "CODENAME";
            dropdownlist.DataValueField = "ID";
            dropdownlist.DataBind();
            dropdownlist.Items.Insert(0, new ListItem("--所有--", ""));
        }
        catch
        {
        }
    }
    
    /// <summary>
    /// 根据部门获取巡店督导
    /// </summary>
    /// <param name="domainid"></param>
    /// <param name="orgvalues"></param>
    /// <param name="dropdownlist"></param>
    public static void BindUsersDDLEX(decimal domainid, string orgvalues, DropDownList dropdownlist)
    {
        try
        {
            //
            dropdownlist.Items.Clear();
            dropdownlist.DataSource = new MobileUserManager().Load(domainid, orgvalues);
            dropdownlist.DataTextField = "CODENAME";
            dropdownlist.DataValueField = "ID";
            dropdownlist.DataBind();
            dropdownlist.Items.Insert(0, new ListItem("--请选择--", ""));
        }
        catch
        {
        }
    }

    
    /// <summary>
    /// 根据部门获取经销商
    /// </summary>
    /// <param name="domainid"></param>
    /// <param name="orgvalues"></param>
    /// <param name="dropdownlist"></param>
    public static void BindChiansDDL(decimal domainid, string orgvalues, DropDownList dropdownlist)
    {
        try
        {
            //
            dropdownlist.Items.Clear();
            dropdownlist.DataSource = new ChainManager().GetCourseTable(domainid, orgvalues);
            dropdownlist.DataTextField = "DESCRIPTION";
            dropdownlist.DataValueField = "ID";
            dropdownlist.DataBind();
            dropdownlist.Items.Insert(0, new ListItem("--所有--", ""));
        }
        catch
        {
        }
    }

    public static void BindChiansDDLByRegion(decimal domainid, string regionList, DropDownList dropdownlist)
    {
        try
        {
            //
            dropdownlist.Items.Clear();
            dropdownlist.DataSource = new ChainManager().GetChainTable(domainid, regionList, "", "1");
            dropdownlist.DataTextField = "DESCRIPTION";
            dropdownlist.DataValueField = "ID";
            dropdownlist.DataBind();
            dropdownlist.Items.Insert(0, new ListItem("--所有--", ""));
        }
        catch
        {
        }
    }
}
